package com.igeek.d0618.test7;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author: zhiyu
 * @Date:19:15
 * @DESC:
 */
public class Test {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
        Class<Person> personClass = Person.class;
        Person person = personClass.newInstance();
        Method setName = personClass.getMethod("setName", String.class);
        setName.invoke(person,"张三");
        Field declaredField = personClass.getDeclaredField("age");
        declaredField.setAccessible(true);
        declaredField.set(person,23);
        System.out.println("person.toString() = " + person.toString());
    }
}
